package com.sudo.boot.service.sys.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.If;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.sudo.boot.mapper.sys.entity.SysJobLog;
import com.sudo.boot.mapper.sys.mapper.SysJobLogMapper;
import com.sudo.boot.mapper.sys.model.bo.SysJobLogBo;
import com.sudo.boot.service.sys.SysJobLogService;
import org.springframework.stereotype.Service;

import static com.sudo.boot.mapper.sys.entity.table.SysJobLogTableDef.SYS_JOB_LOG;

@Service
public class SysJobLogServiceImpl extends ServiceImpl<SysJobLogMapper, SysJobLog> implements SysJobLogService {

    @Override
    public Page<SysJobLog> querySysJobLogByPage(SysJobLogBo bo) {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .where(SYS_JOB_LOG.JOB_ID.eq(bo.getJobId()))
                .and(SYS_JOB_LOG.JOB_RESULT.eq(bo.getJobResult(), If::hasText))
                .and(SYS_JOB_LOG.JOB_ACTION.eq(bo.getJobAction(), If::hasText))
                .orderBy(SYS_JOB_LOG.ID.desc());
        return mapper.paginate(bo.getPageNumber(), bo.getPageSize(), queryWrapper);
    }

    @Override
    public SysJobLog getSysJobLog(Integer id) {
        return mapper.selectOneById(id);
    }
}
